package com.lagou.edu.enums;


import lombok.AllArgsConstructor;

/**
 * 校验验证码是否正确，0 正确 1 验证码错误 2 超时
 * @author zjy
 */
@AllArgsConstructor
public enum CodeStatus{

    /**
     *
     */
    RIGHT(0, "正确"),
    WRONG(1, "验证码错误"),
    TIME_OUT(2, "验证码已失效，请重新获取"),
    OTHER(-1, "邮箱未验证，请获取验证码");

    private int code;
    private String desc;


    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 通过code返回对应的描述信息
     *
     * @param code code
     * @return
     */
    public static String getDesc(Integer code) {
        for (CodeStatus apiCodeEnum : CodeStatus.values()) {
            if (code.equals(apiCodeEnum.getCode())) {
                return apiCodeEnum.getDesc();
            }
        }
        return OTHER.getDesc();
    }
}
